Column

Open case locator

Column

Case details

---
title: "Open lead violations in Syracuse, NY"
output: 
  flexdashboard::flex_dashboard:
    theme: readable
    social: menu
    orientation: columns
    vertical_layout: fill
    source_code: embed 
---

```{r setup, include=FALSE}

library(flexdashboard)
library(sf)
library(tidyverse)
library(leaflet)

# lead violations
# updated by SYR open data on 1/19/2020
lead_viol <- sf::read_sf("https://opendata.arcgis.com/datasets/9870ad89e2af406eb48e127af1429f09_0.geojson")

map_data <- lead_viol %>% 
  mutate(lubridate::year(case_open_date),
         complaint = stringr::str_trim(nature_of_complaint),
         complaint = str_replace_all(complaint, "\r\n" , " "),
         vacant = ifelse(is.na(vacant_property), "No", "Yes"),
         case_open_date = lubridate::as_date(case_open_date)) %>% 
  select(#TNT = TNT_NAME, removed from dataset
         Address = property_address,
         Vacant = vacant,
         Neighborhood = neighborhood,
         Violation = complaint,
         Case = case_number,
         Opened = case_open_date,
         Status = case_status,
         Owner = property_owner_name
  )


```

Column {data-width=400}
-----------------------------------------------------------------------

### Open case locator

```{r leaflet}

center <- map_data %>%
  summarise() %>%
  st_centroid() %>% 
  st_coordinates() %>% 
  as_tibble()

map_data %>% 
  as_Spatial() %>% 
  leaflet() %>%
  setView(lng = center$X,
          lat = center$Y,
          zoom = 12) %>% 
  addTiles() %>% 
  addCircles(label = ~Address)

```

Column {data-width=600}
-----------------------------------------------------------------------

### Case details

```{r}

map_data %>% 
  st_set_geometry(NULL) %>% 
  mutate_at(vars(
    Vacant, Neighborhood,
    Case, Status, Owner),
    as.factor) %>% 
  DT::datatable(rownames = FALSE,
                filter = "top",
                extensions = "Buttons",
                options = list(
                  autoWidth = TRUE,
                  columnDefs = list(list(width = '130px', 
                                         targets = c(0,2,3,5))),
                  dom = 'Bfrtip',
                  buttons = c('csv', 'excel', 'print')
                ),
                caption = htmltools::tags$caption(
                  
                  style = 'caption-side: bottom; text-align: right;',
                  'Case details as of 1/19/2020.  Source: data.syrgov.net')
  )

```